﻿Imports IICModel.BusObjects.Mappers
Imports IICModel.BusObjects

Namespace DataConbversionLogic
    Public Class LessonsCache

        Private lesdb As New LessonDBMapper
        Private _lessonsCache As Dictionary(Of String, Lesson)

        Private Shared _Cache As LessonsCache

        Public Shared Function current() As LessonsCache

            If _Cache Is Nothing Then
                _Cache = New LessonsCache

            End If

            Return _Cache

        End Function


        Private Sub New()

            Me._lessonsCache = New Dictionary(Of String, Lesson)
            Call createPASLessons()

        End Sub

        Public Function getLessonByCode(ByVal lessonCode As String) As Lesson

            If Me._lessonsCache.ContainsKey(lessonCode) = False Then
                Dim tmpLesson As Lesson = lesdb.findWhere("lessoncode={0}", lessonCode)
                Me._lessonsCache.Add(lessonCode, tmpLesson)
            End If

            Return Me._lessonsCache.Item(lessonCode)

        End Function

        Private Sub createPASLessons()

            Dim less As Lesson

            less = lesdb.findWhere("lessoncode={0}", "GR10")
            If less Is Nothing Then
                less = LessonFactory.Create
                less.LessonCode = "GR10"
                less.LessonName = "Η Ιδιωτική Ασφάλιση"
                less.DefaultPassGrade = 110
                less.DefaultMaxGrade = 200
                lesdb.save(less)
            End If

            less = lesdb.findWhere("lessoncode={0}", "745")
            If less Is Nothing Then
                less = LessonFactory.Create
                less.LessonCode = "745"
                less.LessonName = "Αρχές Ασφάλισης Περιουσίας"
                less.DefaultPassGrade = 110
                less.DefaultMaxGrade = 200
                lesdb.save(less)
            End If


            less = lesdb.findWhere("lessoncode={0}", "735")
            If less Is Nothing Then
                less = LessonFactory.Create
                less.LessonCode = "735"
                less.LessonName = "Ασφάλίσεις Ζωής"
                less.DefaultPassGrade = 110
                less.DefaultMaxGrade = 200
                lesdb.save(less)
            End If

            less = lesdb.findWhere("lessoncode={0}", "765")
            If less Is Nothing Then
                less = LessonFactory.Create
                less.LessonCode = "765"
                less.LessonName = "Ασφάλιση Μηχανοκίνητων Οχημάτων"
                less.DefaultPassGrade = 110
                less.DefaultMaxGrade = 200
                lesdb.save(less)
            End If

            less = lesdb.findWhere("lessoncode={0}", "530")
            If less Is Nothing Then
                less = LessonFactory.Create
                less.LessonCode = "530"
                less.LessonName = "Επιχειρηματικό και Οικονομικό Περιβάλλον"
                less.DefaultPassGrade = 110
                less.DefaultMaxGrade = 200
                lesdb.save(less)
            End If
        End Sub

    End Class
End Namespace
